package com.budwk.app.util.poiUtils;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.Map;

import static com.budwk.app.util.poiUtils.CommonFormOfficeUtils.addWordPicture;
import static com.budwk.app.util.poiUtils.CommonFormOfficeUtils.generateWordDocument;

/**
 * @author ZY.Wang
 * @since 2023/8/3
 */
public class SitePictureOfficeUtils {

    public static ByteArrayOutputStream createSitePicture(List<SitePictureContent> contentDTOList) {
        long startTime = System.currentTimeMillis();

        Map<String, Object> paramMap = popularParamMap(contentDTOList);
        if (paramMap == null) return null;

        String templateName = "pictures.docx";
        return generateWordDocument(paramMap, templateName, "现场照片", startTime);
    }

    public static Map<String, Object> popularParamMap(List<SitePictureContent> contentDTOList) {
        if (contentDTOList.size() == 0) return null;

        Map<String, Object> paramMap = Maps.newHashMap();

        List<Map<String, Object>> contentList = Lists.newArrayList();
        for (SitePictureContent sitePictureContent : contentDTOList) {
            Map<String, Object> contentItem = Maps.newHashMap();
            contentItem.put("text", sitePictureContent.getTextStr());
            contentItem.put("pictures", addWordPicture(sitePictureContent.getPictureList(), "picture", 15F, 12.5F));

            contentList.add(contentItem);
        }

        paramMap.put("content", contentList);

        return paramMap;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class SitePictureContent {
        private String textStr;
        private List<String> pictureList;
    }
}
